<template>
  <div class="scroll-category">
    <div class="product-tabs-outer">
      <div class="product-tabs">
        <!-- 活动专区 -->
        <div class="tabs-list" v-if="type==='1'">
          <div 
            class="item" 
            :class="{'item-cur': currentIndex === item.id && hasCurrent}"
            v-for="(item, index) in categories" 
            :key="index"
            @click="tabClicked(item, index)"
          >
            {{item.Name}}
          </div>
        </div>

        <!-- 商品分类 -->
        <div class="tabs-list" v-if="type==='0'">
          <div 
            class="item" 
            :class="{'item-cur': currentIndex === index && hasCurrent}"
            v-for="(item, index) in categories" 
            :key="index"
            @click="tabClicked(item, index)"
          >
            {{item.Name}}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    categories: {
      type: Array,
      default: [],
    },
    currentIndex: {
      type: Number,
      default: 0,
    },
    hasCurrent: {
      type: Boolean,
      default: true,
    },
    type: {
      type: String,
      default: 0,
    },
  },
  methods: {
    tabClicked(item, index){
      this.$emit('itemClicked', {item, index})
    }
  },
}
</script>

<style scoped>
.product-tabs-outer{
  overflow: hidden;
  margin-bottom: 10px;
}
.product-tabs{
  width: 100%;
  overflow: auto;
  margin-top: 18px;
  padding-bottom: 20px;
  margin-bottom: -20px;
}
.product-tabs::-webkit-scrollbar{
  width: 0;
  -webkit-overflow-scrolling: touch;
  -ms-overflow-style: none;
  overflow: -moz-scrollbars-none;
  height: 0;
  background-color: rgba(240,240,240,0)
}
.product-tabs .tabs-list{
  display: flex;
}
.product-tabs .tabs-list .item:first-child{
  text-align: left;
  padding-left: 0;
}
.product-tabs .tabs-list .item{
  position: relative;
  flex-shrink: 0;
  min-width: 35px;
  padding: 0 17px;
  height: 38px;
  line-height: 38px;
  border-radius: 5px;
  margin-left: 10px;
  text-align: center;
  font-size: 16px;
  color: #B0AFAF;
}
.product-tabs .tabs-list .item-cur{
  color: #000;
  font-weight: bold;
}
.product-tabs .tabs-list .item-cur:after{
  position: absolute;
  display: block;
  content: '';
  left: 19px;
  right: 19px;
  bottom: 0;
  height: 2px;
  border-radius: 2px;
  background-color: #000;
}
.product-tabs .tabs-list .item-cur:first-child:after{
  left: 0;
}

/* active-switch */
.active-switch .product-tabs{
  overflow: hidden;
  padding-left: 10px;
  padding-right: 10px;
  box-sizing: border-box;
}
.active-switch .product-tabs .tabs-list{
  justify-content: flex-start;
}
.active-switch .product-tabs .tabs-list .item{
  width: 32%;
  margin-right: 2%;
  font-size: 18px;
  margin-left: 0;
  box-sizing: border-box;
}
.active-switch .product-tabs .tabs-list .item:after{
  left: 23px;
  right: 23px;
}
.active-switch .product-tabs .tabs-list .item:first-child{
  padding-left: 17px;
  text-align: center;
}
</style>